<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:jee="http://java.sun.com/xml/ns/javaee"
	version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:import href="dump.xsl" />

	<xsl:variable name="web.xml" select="'../web.xml'" />
	<xsl:variable name="web.xml.doc" select="document($web.xml)" />

	<xsl:key name="srv-by-name"  match="jee:servlet" use="jee:servlet-name" />
	<xsl:key name="srv-by-class" match="jee:servlet" use="jee:servlet-class" />

	<xsl:variable name="title">
		<xsl:variable name="cn" select="/*/ClassName" />
		<h1>
			<xsl:for-each select="$web.xml.doc">
				<xsl:variable name="s" select="key('srv-by-class', $cn)" />
				<xsl:value-of select="($s/jee:display-name | $s/jee:servlet-name)[1]" />
			</xsl:for-each> (<xsl:value-of select="$cn"/>)</h1>
	</xsl:variable>

	<xsl:template match="/" mode="content"/>
	<xsl:template match="/" mode="css"/>

	<xsl:template match="/">
		<html>
			<head>
				<title>
					<xsl:value-of select="$title" />
				</title>
				<style type="text/css">
					<xsl:apply-templates select="." mode="css"/>
				</style><!--
http://yui.yahooapis.com/2.3.1/build/reset-fonts-grids/reset-fonts-grids.css -->
				<link rel="stylesheet" type="text/css" href="reset-fonts-grids.css"/>
				<link rel="stylesheet" type="text/css" href="dump.css" />
				<link rel="stylesheet" type="text/css" href="xpgj.css" />
			</head>
			<body>
				<xsl:copy-of select="$title" />
				<ul id="web-xml">
					<xsl:apply-templates select="$web.xml.doc/*" mode="list" />
				</ul>
				<div id="content" class="clr">
					<xsl:apply-templates select="." mode="content"/>
				</div>
				<xsl:apply-templates select="." mode="xml" />
				<xsl:apply-templates select="$web.xml.doc" mode="xml" />
			</body>
		</html>
	</xsl:template>

	<xsl:template match="*" mode="list">
		<xsl:apply-templates select="*" mode="list" />
	</xsl:template>

	<xsl:template match="jee:servlet-mapping" mode="list">
		<li
			title="{concat(jee:url-pattern, ' &#x2192; ', key('srv-by-name', jee:servlet-name)/jee:servlet-class)}">
			<a href="{substring(jee:url-pattern,2)}">
				<xsl:value-of select="jee:servlet-name" />
			</a>
		</li>
	</xsl:template>


	<xsl:template match="@*|node()">
		<xsl:copy>
			<xsl:apply-templates select="@*|node()" />
		</xsl:copy>
	</xsl:template>

</xsl:stylesheet>
